<?php

/**
 * This is the model class for table "task_analyst_special".
 *
 * The followings are the available columns in table 'task_analyst_special':
 * @property integer $id_task_analyst_special
 * @property integer $id_task_analyst
 * @property string $quantity
 * @property string $subject
 * @property string $weight_ct
 * @property string $length_diameter_1
 * @property string $width_diameter_1
 * @property string $thickness
 * @property string $size
 * @property string $comment
 * @property string $other_1
 * @property string $orther_2
 * @property string $final_certif
 * @property string $invoice_certif
 * @property string $cleaning_bill
 * @property string $gtl_ref
 * @property string $weight
 * @property string $size_2
 * @property string $dimensions
 * @property string $packing
 */
class TaskAnalystSpecial extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return TaskAnalystSpecial the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'task_analyst_special';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_task_analyst', 'required'),
			array('id_task_analyst', 'numerical', 'integerOnly'=>true),
			array('quantity, subject, weight_ct, length_diameter_1, width_diameter_1, thickness, size, comment, other_1, orther_2, final_certif, invoice_certif, cleaning_bill, gtl_ref, weight, size_2, dimensions, packing', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_task_analyst_special, id_task_analyst, quantity, subject, weight_ct, length_diameter_1, width_diameter_1, thickness, size, comment, other_1, orther_2, final_certif, invoice_certif, cleaning_bill, gtl_ref, weight, size_2, dimensions, packing', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(

		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_task_analyst_special' => 'Id Task Analyst Special',
			'id_task_analyst' => 'Id Task Analyst',
			'quantity' => 'Quantity',
			'subject' => 'Subject',
			'weight_ct' => 'Weight Ct',
			'length_diameter_1' => 'Length Diameter 1',
			'width_diameter_1' => 'Width Diameter 1',
			'thickness' => 'Thickness',
			'size' => 'Size',
			'comment' => 'Comment',
			'other_1' => 'Other 1',
			'orther_2' => 'Orther 2',
			'final_certif' => 'Final Certif',
			'invoice_certif' => 'Invoice Certif',
			'cleaning_bill' => 'Cleaning Bill',
			'gtl_ref' => 'Gtl Ref',
			'weight' => 'Weight',
			'size_2' => 'Size 2',
			'dimensions' => 'Dimensions',
			'packing' => 'Packing',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_task_analyst_special',$this->id_task_analyst_special);
		$criteria->compare('id_task_analyst',$this->id_task_analyst);
		$criteria->compare('quantity',$this->quantity,true);
		$criteria->compare('subject',$this->subject,true);
		$criteria->compare('weight_ct',$this->weight_ct,true);
		$criteria->compare('length_diameter_1',$this->length_diameter_1,true);
		$criteria->compare('width_diameter_1',$this->width_diameter_1,true);
		$criteria->compare('thickness',$this->thickness,true);
		$criteria->compare('size',$this->size,true);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('other_1',$this->other_1,true);
		$criteria->compare('orther_2',$this->orther_2,true);
		$criteria->compare('final_certif',$this->final_certif,true);
		$criteria->compare('invoice_certif',$this->invoice_certif,true);
		$criteria->compare('cleaning_bill',$this->cleaning_bill,true);
		$criteria->compare('gtl_ref',$this->gtl_ref,true);
		$criteria->compare('weight',$this->weight,true);
		$criteria->compare('size_2',$this->size_2,true);
		$criteria->compare('dimensions',$this->dimensions,true);
		$criteria->compare('packing',$this->packing,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

    public static function getValueSpecialByTask($id_task = null, $dataReturn = null){
        if(is_null($id_task) || empty($id_task) || is_null($dataReturn))
            return false;

        $criteria = new CDbCriteria();
        $criteria->with = array('analyst_special');
        $criteria->addCondition('t.id_task = :id_task');
        $criteria->addCondition('t.del_flg = :del_flg');
        $criteria->params = array(
            ':id_task' => $id_task,
            ':del_flg' => 0,
        );

        $taskAnalystModel = TaskAnalyst::model()->findAll($criteria);
        if(!$taskAnalystModel)
            return false;
        foreach ($taskAnalystModel as $data){
            if(isset($data->analyst_special->{$dataReturn}) && $data->analyst_special->{$dataReturn})
                return $data->analyst_special->{$dataReturn};
        }

        return false;
    }
}